<?php
class Dekorasi extends CI_Controller{
    var $_public_view;

    function __construct() {
        parent::__construct();
        $this->load->model('model_listing', 'mlisting');
        $this->load->model('model_properti_baru', 'mpropbaru');
        $this->load->helper('url','site');
        $this->load->helper('form');
        $this->load->library('session');
        $this->config->load('artyproperty');
        $this->_public_view = $this->config->item('public_view');
    }

    function index(){
        $str_id = '';
        //cek session
        $islogin = $this->session->userdata('isLogin');
        $user = '';
        if ($islogin) {
            $user = $this->session->userdata('username');
        }
        $data_output = array();
        $sql = "select * from desain";
        $query = $this->db->query($sql);
        
        $count = 0;
        if($query->num_rows() > 0){
            //print_r($query->result());
            $result = $query->result();
            foreach ($result as $row) {
                $data_output['dekorasi'][$count]['id'] = $row->dekorasi_id;    
                $data_output['dekorasi'][$count]['nama'] = $row->nama_dekorasi; 
                $data_output['dekorasi'][$count]['url'] = $row->url; 
                $count++;
            }   
            //print_r($result);       
        }
        //$data_output['dekorasi']['dekorasi_id'] = $dekorasi->dekorasi_id;

        $this->session->set_userdata('page',3);

        $data = array(
            'output' => $data_output,
            'page_title' => 'Desain dan Dekorasi',
            'page_content' => 'dekorasi',
            'prop_baru' => $this->mpropbaru->get_properti_baru(),
            'isLogin' => $islogin,
            'user' => $user);
        $this->load->view($this->_public_view, $data);        
    }

    function detail() {
        $str_id = '';
        //cek session
        $islogin = $this->session->userdata('isLogin');
        $user = '';
        if ($islogin) {
            $user = $this->session->userdata('username');
        }
        if ($this->uri->segment(3) == FALSE) {
            redirect('dekorasi', 'location');
        } else {
            $str_id = $this->uri->segment(3);
        }

        $data_output = array();
        $sql = "select * from desain where dekorasi_id = ?";
        $query = $this->db->query($sql,$str_id);
        $dekorasi = $query->row();
        $data_output['dekorasi']['nama_dekorasi'] = $dekorasi->nama_dekorasi;
        $data_output['dekorasi']['estimasi_harga'] = $dekorasi->estimasi_harga;
        $data_output['dekorasi']['estimasi_luas'] = $dekorasi->estimasi_luas;
        $data_output['dekorasi']['user_id'] = $dekorasi->user_id;

        $sql = "select * from user,desain where user.user_id = desain.user_id";
        $query = $this->db->query($sql, $str_id);
        $agen = $query->row();
        $data_output['agen']['nama_depan'] = $agen->nama_depan;
        $data_output['agen']['nama_belakang'] = $agen->nama_belakang;
        $data_output['agen']['no_hp'] = $agen->no_hp;
        $data_output['agen']['pin_bb'] = $agen->pin_bb;

        $data = array(
            'output' => $data_output,
            'page_content' => 'detail_dekorasi',
            'page_title' => 'Detail Desain dan Dekorasi',
            'isLogin' => $islogin,
            'user' => $user);
        $this->load->view($this->_public_view, $data);
    }

}
?>
